package com.template.ejb.rest.exception;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

/**
 * 
 * 
 */
@Provider
public class WebServiceExceptionMapper implements ExceptionMapper<Exception> {

	/**
	 * 
	 */
	public Response toResponse(Exception exception) {

		if (exception instanceof IllegalAccessException) {
			return Response.status(Status.INTERNAL_SERVER_ERROR).entity(
					exception.getMessage()).type(MediaType.TEXT_PLAIN).build();
		}
		if (exception instanceof IllegalArgumentException) {
			return Response.status(Status.INTERNAL_SERVER_ERROR).entity(
					exception.getMessage()).type(MediaType.TEXT_PLAIN).build();
		} else {
			return Response.status(Status.INTERNAL_SERVER_ERROR).entity(
					exception.getMessage()).type(MediaType.TEXT_PLAIN).build();
		}
	}
}
